import jieba
import wordcloud
import mysqldb_server
import os


def get_wordcloud_info(username, friend_username):
    print("开始生成词云")
    res = mysqldb_server.find_all_messages(username, friend_username)
    str_all_messages = ""
    for i in res:
        one_message = i[0]
        str_all_messages = str_all_messages+one_message
    print(str_all_messages)
    cut_txt = jieba.cut(str_all_messages)
    result = " ".join(cut_txt)
    print(result)
    print(" ".join(jieba.cut("我正在通过TCP给程序员发送信息")))
    wc = wordcloud.WordCloud(
            # font_path="C:/Windows/Fonts/simhei.ttf",
            # mac专用字体格式
            font_path='STHeiti Medium.ttc',
            background_color='white',
            max_font_size=100,
            max_words=1000,
            width=600,
            height=400
        )
    wc.generate(result)
    filename = str(username)+".png"
    wc.to_file(filename)
    file_path = os.path.join(os.getcwd(),filename)
    print(file_path)
    return file_path
    #

if __name__ == '__main__':
    import os
    print(os.getcwd())
    get_wordcloud_info("15133854715","17849327316")